<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" :inline="true" :rules="Rules" label-width="auto"
                 @submit.native.prevent>
            <el-form-item label="字段名称" desc="" prop="filedName">
                <el-input v-model.trim="formData.filedName" placeholder="" clearable size="small"
                          style="width:120px;" />
            </el-form-item>
            <el-form-item label="字段名称中文" desc="" prop="filedNameChinese">
                <el-input v-model.trim="formData.filedNameChinese" placeholder="" clearable size="small"
                          style="width:120px;" />
            </el-form-item>
            <el-form-item label="字段类型" desc="" prop="filedType">
                <dic-select v-model="formData.filedType" :code="dicInner.g_field_filedType" placeholder="" clearable
                            size="small" style="width:120px;" />
            </el-form-item>
        <!--    <el-form-item label="字段对应" desc="" prop="gTableId">
                <el-input v-model.trim="formData.gTableId" placeholder="" clearable size="small" style="width:120px;" />
            </el-form-item>-->
        </el-form>
    </div>
</template>
<script>  import { getUrlParam } from '@/utils/index';
import { alertWithPaylod } from '@/utils/alertUtil';
import * as  api from '@/apis/gTableFeild.api.js';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import { fillData, validatePromise } from '@/utils/index';

const Rules = {
  'id': [{ required: false, message: '', trigger: 'blur' }],
  'filedName': [{ required: true, message: '', trigger: 'blur' }],
  'filedNameChinese': [{ required: true, message: '', trigger: 'blur' }],
  'filedType': [{ required: true, message: '', trigger: 'blur' }],
  'gTableId': [{ required: false, message: '', trigger: 'blur' }],
  'delState': [{ required: false, message: '', trigger: 'blur' }],
};
const dicInner = {
  '___g_field_id': '',
  'g_field_id': 'g_field_id',
  '___g_field_filedName': '',
  'g_field_filedName': 'g_field_filedName',
  '___g_field_filedNameChinese': '',
  'g_field_filedNameChinese': 'g_field_filedNameChinese',
  '___g_field_filedType': '',
  'g_field_filedType': 'g_field_filedType',
  '___g_field_gTableId': '',
  'g_field_gTableId': 'g_field_gTableId',
  '___g_field_delState': '',
  'g_field_delState': 'g_field_delState',
};
export default {
  name: 'gFieldModify',
  data() {
    return {
      api: api,
      Rules,
      dicInner,
      formData: { 'id': '', 'filedName': '', 'filedNameChinese': '', 'filedType': '', 'gTableId': '', 'delState': '' },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
  },
  computed: {},
  watch: {},
  methods: {
    /**       *  @params _data.         * @desc 初始化        */      initByDialog(_data) {
      fillData(this.formData, _data);
      console.log('初始化数据', this.formData);
    }, async submitByDialog(_data) {
      var isyes = await validatePromise.call(this, 'queryForm');
      if (!isyes) {
        return { success: false, message: '请检查必填项' };
      }
      if(this.formData.gTableId/*有父类id 才可以单独保存这个*/){
        var func = this.formData.id ? api.update : api.add;
        var result = await func(this.formData);
        alertWithPaylod(result);
        return result;
      }else{
      return {success:true,data:this.formData}
      }
      
    },
  },
};</script>
